/**
 *
 */
package org.msfj.common.exception;

import org.msfj.common.enums.HttpCode;
import cn.hutool.core.util.StrUtil;
import org.springframework.ui.ModelMap;

/**
 * @Description: 错误信息基础类
 * @Author: like
 * @Date: 2017-10-20 15:49
 * @Version: 1.0
 * @Created in idea by autoCode
 */
@SuppressWarnings("serial")
public abstract class BaseException extends RuntimeException {
    private int status = 500;

    public int getStatus() {
        return status;
    }

    protected abstract HttpCode getHttpCode();

    public void setStatus(int status) {
        this.status = status;
    }

    public BaseException(String message, int status) {
        super(message);
        this.status = status;
    }

    public BaseException() {
    }

    public BaseException(Throwable ex) {
        super(ex);
    }

    public BaseException(String message) {
        super(message);
    }

    public BaseException(String message, Throwable ex) {
        super(message, ex);
    }

    public void handler(ModelMap modelMap) {
        modelMap.put("httpCode", getHttpCode().value());
        if (StrUtil.isNotBlank(getMessage())) {
            modelMap.put("msg", getMessage());
        } else {
            modelMap.put("msg", "");
        }
        modelMap.put("timestamp", System.currentTimeMillis());
    }
}
